package zelix.hack.hacks;

import zelix.hack.Hack;
import zelix.hack.HackCategory;
import zelix.utils.system.Connection;
import zelix.utils.system.Mapping;
import zelix.value.BooleanValue;
import zelix.utils.Wrapper;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.CPacketEntityAction;
import net.minecraft.network.play.client.CPacketPlayer;
import static net.minecraft.network.play.client.CPacketEntityAction.Action.START_SPRINTING;
import static net.minecraft.network.play.client.CPacketEntityAction.Action.STOP_SPRINTING;
import net.minecraftforge.fml.relauncher.ReflectionHelper;

public class AntiHunger extends Hack
{
    public static BooleanValue sprint = new BooleanValue("Sprint",false);
    public static BooleanValue ground = new BooleanValue("Ground",false);


    public AntiHunger()
    {
        super("AntiHunger", HackCategory.PLAYER);
        addValue(sprint,ground);
    }

    @Override
    public boolean onPacket(Object packet, Connection.Side side) {
        if ((Packet)packet instanceof CPacketPlayer && ground.getValue() && !Wrapper.INSTANCE.player().isElytraFlying())
        {
            final CPacketPlayer l_Packet = (CPacketPlayer) packet;
            if (Wrapper.INSTANCE.player().fallDistance > 0 || Wrapper.INSTANCE.controller().getIsHittingBlock())
            {
                ReflectionHelper.setPrivateValue(CPacketPlayer.class,l_Packet,true, Mapping.onGround);

            }
            else
            {
                ReflectionHelper.setPrivateValue(CPacketPlayer.class,l_Packet,false,Mapping.onGround);
            }
        }

        if ((Packet)packet instanceof CPacketEntityAction && sprint.getValue())
        {
            final CPacketEntityAction l_Packet = (CPacketEntityAction) packet;
            if (l_Packet.getAction() == START_SPRINTING || l_Packet.getAction() == STOP_SPRINTING)
            {
                return false;
            }
        }
        return  true;

    }
}
